﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Phim : System.Web.UI.Page
{
    ClassPhim cphim = new ClassPhim();
    protected void Page_Load(object sender, EventArgs e)
    {
            if (Request.QueryString["idphim"] == null)
            {
                CollectionPager1.PageSize = 8;
                CollectionPager1.DataSource = cphim.DS_Phim().DefaultView;
                CollectionPager1.BindToControl = DataList1;

                DataList1.DataSource = CollectionPager1.DataSourcePaged;
                DataList1.DataBind();
            }
            else
            {
                CollectionPager1.PageSize = 8;
                CollectionPager1.DataSource = cphim.Tim_Phim(Request.QueryString["idphim"]).DefaultView;
                CollectionPager1.BindToControl = DataList1;

                DataList1.DataSource = CollectionPager1.DataSourcePaged;
                DataList1.DataBind();
            }
    }
    protected void DataList1_ItemCommand1(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "thue")
        {
            if (Session["user"] == null)
                lbInform.Text = "Bạn phải đăng nhập để thuê đĩa";
            else
            {
                DataTable dtb;
                if (Session["GioHang"] == null)
                {
                    dtb = new DataTable();
                    dtb.Columns.Add("MaPhim", typeof(string));
                    dtb.Columns.Add("TenPhim", typeof(string));
                    dtb.Columns.Add("SoMuon", typeof(int));
                    dtb.Columns.Add("GiaThue", typeof(float));
                    dtb.Columns.Add("ThanhTien", typeof(float), "SoMuon*GiaThue");
                    dtb.PrimaryKey = new DataColumn[] { dtb.Columns[0] };
                    Session["GioHang"] = dtb;
                }
                else
                    dtb = (DataTable)Session["GioHang"];
                HyperLink Ten = (HyperLink)e.Item.FindControl("hlChiTiet");
                Label Gia = (Label)e.Item.FindControl("lbGia");
                dtb.Rows.Add(e.CommandArgument.ToString(), Ten.Text, 1, Gia.Text);
                Session["GioHang"] = dtb;
                lbInform.Text = "";
            }
        }
        else
        {
            Response.Redirect("ChiTietPhim.aspx?idcd=" + e.CommandArgument.ToString());
        }
    }
}
